import fetch from 'common/src/utils/fetch';
import UTILS from "common/src/utils/utils";
import cryp from 'common/src/utils/secret'
/**
 * 查询学生关联培养方案列表
 */
export function findStudentCultureRelList(data) {
    let newData = Object.assign({}, data);
    if(newData.trainingCategory && newData.trainingCategory instanceof Array) {
      newData.trainingCategory = newData.trainingCategory.join(",");
    }
    return fetch({
        url: '/api/cultureservice/studentCultureRel/findStudentCultureRelList',
        method: 'post',
        data: newData
    });
}
/**
 * 批量修改学生第一外国语对应的课程信息
 */
export function batchUpdateFirstLanguageCourses(data) {
    return fetch({
        url:
            '/api/cultureservice/studentCultureRel/batchUpdateFirstLanguageCourses',
        method: 'PUT',
        data
    });
}
/**
 * 查询学生个人计划列表
 * isPass研究生默认为0，本科生存在0和1的状态
 */
export function getCulturePlanByStudentId(id, isPass = 0) {
    return fetch({
        url:
            '/api/cultureservice/culturePlan/getCulturePlanByStudentId?id=' +
            id +
            '&isPass=' +
            isPass,
        method: 'GET'
    });
}
/**
 * 查询学生个人计划列表(首页查询处理)
 * isPass研究生默认为0，本科生存在0和1的状态
 */
export function getCulturePlanByStudentIdAndIsPass(id, isPass = 0) {
    return fetch({
        url:
            '/api/cultureservice/culturePlan/getCulturePlanByStudentIdAndIsPass?id=' +
            id +
            '&isPass=' +
            isPass,
        method: 'GET'
    });
}
/**
 * 查询学生指定分类下的课程列表
 */
export function getCultureCourseByParam(
    studentId,
    labelId,
    nature,
    college,
    term,
    isElective,
    pageNum_,
    pageSize_,
    templateId
) {
    let url =
        '/api/cultureservice/culturePlan/getCouresListByStudentIdAndLabelId?studentId=' +
        studentId +
        '&labelId=' +
        labelId;
    if (templateId) {
        url += '&templateId=' + templateId;
    }
    if (nature) {
        url += '&nature=' + nature;
    }
    if (college) {
        url += '&college=' + college;
    }
    if (term) {
        url += '&term=' + term;
    }
    if (isElective) {
        url += '&isElective=' + isElective;
    }
    if (pageNum_) {
        url += '&pageNum_=' + pageNum_;
    }
    if (pageSize_) {
        url += '&pageSize_=' + pageSize_;
    }
    return fetch({
        url: url,
        method: 'GET'
    });
}

/**
 * 学生提交自己的培养计划
 * status=2，存草稿
 * status=3，提交审批
 */
export function saveCulturePlan(data, studentId, status, teacherId = "null") {
    return fetch({
        url: `/api/cultureservice/culturePlan/saveCulturePlan/${studentId}/${status}/${teacherId}`,
        method: 'POST',
        data
    });
}

/**
 * 学生更新自己的培养计划
 * status=2,更新草稿
 * status=3,更新且提交审批
 */
export function updateCulturePlan(data, studentId, status, teacherId = "null") {
    return fetch({
        url: `/api/cultureservice/culturePlan/updateCulturePlan/${studentId}/${status}/${teacherId}`,
        method: 'PUT',
        data
    });
}

/**
 * 查看学生关联培养方案详情
 */
export function findStudentCultureRelById(studentId) {
    return fetch({
        url:
            '/api/cultureservice/studentCultureRel/findStudentCultureRelByStudentId?stuid=' +
            cryp.encrypt(studentId),
        method: 'GET'
    })
}
/** 
 * 更新个人培养计划的状态
 * 无数据的变化
 */
export function updateStudentCultureRelStatus(studentId, status, teacherId) {
    return fetch({
        url:
            '/api/cultureservice/studentCultureRel/updateStudentCultureRelStatus?studentId=' +
            studentId +
            '&status=' +
            status +
            '&teacherId=' +
            teacherId,
        method: 'PUT'
    });
}
/**
 * 查询个人培养计划历史记录
 */
export function culturePlanActionHistory(studentId) {
    return fetch({
        url: '/api/cultureservice/culturePlanActionHistory/' + studentId,
        method: 'GET'
    });
}
/**
 * 自动绑定第一外国语
 */
export function autoUpdateFirstLanguageCourses(data) {
    return fetch({
        url:
            '/api/cultureservice/studentCultureRel/autoUpdateFirstLanguageCourses',
        method: 'PUT',
        data,
        showMask: false
    });
}
/**
 *
 * @param {获取自动绑定结果} key
 */
export function getAutoUpdateResult(key) {
    return fetch({
        url: '/api/cultureservice/studentCultureRel/result/' + key,
        method: 'GET',
        showMask: false
    });
}
/**
 * 查询多个学院下的专业
 */
export function queryList(data) {
    return fetch({
        url: '/api/commonservice/dictionary/queryList',
        method: 'POST',
        data
    });
}

// 批量删除课程
export function batchDelete(data) {
    return fetch({
        url: '/api/cultureservice/studentCultureRel/courses',
        method: 'DELETE',
        data,
        showMask: false
    });
}

// 批量替换课程
export function batchReplace(data) {
    return fetch({
        url: '/api/cultureservice/studentCultureRel/courses',
        method: 'PUT',
        data,
        showMask: false
    });
}

// 批量新增课程
export function batchAdd(data) {
    return fetch({
        url: '/api/cultureservice/studentCultureRel/courses',
        method: 'POST',
        data,
        showMask: false
    });
}
// 批量操作结果
export function batchResult(key) {
    return fetch({
        url: '/api/cultureservice/studentCultureRel/result/' + key,
        method: 'GET',
        showMask: false
    });
}
// 培养计划统计
export function courseSelection(data) {
    return fetch({
        url: '/api/cultureservice/culturePlan/courseSelection',
        method: 'POST',
        data
    });
}

// 个人计划选课统计列表查询
export function selectCoursesCountList(data) {
    return fetch({
        url: '/api/cultureservice/culturePlan/selectCoursesCountList',
        method: 'POST',
        data
    });
}

// 查询及格学生
export function findScorePassCountStudent(data) {
    return fetch({
        url: '/api/cultureservice/culturePlan/findScorePassCountStudent',
        method: 'POST',
        data
    });
}

// 查询不及格学生信息
export function findNoScorePassCountStudent(data) {
    return fetch({
        url: '/api/cultureservice/culturePlan/findNoScorePassCountStudent',
        method: 'POST',
        data
    });
}

// 查询未选课学生信息
export function findNoSelCourseCountStudent(data) {
    return fetch({
        url: '/api/cultureservice/culturePlan/findNoSelCourseCountStudent',
        method: 'POST',
        data
    });
}

// 查询已选课学生信息
export function findSelCourseCountStudent(data) {
    return fetch({
        url: '/api/cultureservice/culturePlan/findSelCourseCountStudent',
        method: 'POST',
        data
    });
}

// 个人计划跨专业选课获取课程列表
export function transdisciplinaryCourseList(data) {
    return fetch({
        url: '/api/cultureservice/culturePlan/transdisciplinaryCourseList',
        method: 'POST',
        data
    });
}

// 个人计划跨专业选课保存
export function saveTransdisciplinaryCourse(data) {
    return fetch({
        url: '/api/cultureservice/culturePlan/saveTransdisciplinaryCourse',
        method: 'POST',
        data
    });
}

// 导出未选课名单
export function exportNoSelCourseCountStudentInfo(queryForm) {
    // queryForm["x-token"] = sessionStorage.getItem("sessionid") || "";
    let url =
        '/api/cultureservice/culturePlan/exportNoSelCourseCountStudentInfo';
    let queryParam = '';
    for (let key in queryForm) {
        // 去掉空参数
        if (
            key === 'pageNum_' ||
            key === 'pageSize_' ||
            key === 'total_' ||
            queryForm[key] === ''
        ) {
            continue;
        }
        queryParam += `${key}=${queryForm[key]}&`;
    }
    window.open(`${url}?${queryParam}`);
}
// 跨院系选课设置保存
export function chooseCourseForCrossFaultySubmit(data) {
    return fetch({
        url: '/api/cultureservice/courseSelectSet/addOrEditCourseSelectSet',
        method: 'POST',
        data
    });
}
// 跨院系选课设置查询
export function chooseCourseForCrossFaultyFind() {
    return fetch({
        url: '/api/cultureservice/courseSelectSet/findCourseSelectSet',
        method: 'GET',
    });
}
// 跨院系选课设置-学生信息查询
export function findStudentInfoByIdList(data) {
    return fetch({
        url: '/api/cultureservice/courseSelectSet/findStudentInfoByIdList',
        method: 'POST',
        data
    });
}
//批量修改培养计划-批量修改
export function batchUpdate(id, oldCode, newCode) {
    return fetch({
        url:
            '/api/cultureservice/BatchOperaterPlan/batchupdate/?cultureID=' +
            id +
            '&oldCourseCode=' +
            oldCode +
            '&newCourseCode=' +
            newCode,
        method: 'GET'
    });
}
//批量修改培养计划-批量新增
export function batchPlanAdd(id, labid, courseid) {
    return fetch({
        url:
            '/api/cultureservice/BatchOperaterPlan/batchAdd/?cultureID=' +
            id +
            '&labid=' +
            labid +
            '&courseid=' +
            courseid,
        method: 'GET'
    });
}
//批量修改培养计划-批量删除
export function batchPlanDelete(id, oldCode) {
    return fetch({
        url:
            '/api/cultureservice/BatchOperaterPlan/batchdelete/?cultureID=' +
            id +
            '&oldCourseCode=' +
            oldCode,
        method: 'GET'
    });
}
//我的培养计划-学分完成情况
export function studentPlanCountByStuId(id) {

    return fetch({
        url:
            '/api/cultureservice/culturePlan/studentPlanCountByStuId/?studentId=' +
            cryp.encrypt(id),
        method: 'GET'
    });
}
//获取角色分权
export function getPower() {
    return fetch({
        url: '/api/cultureservice/PowerContron/getPower',
        method: 'GET',
    });
}

// 导出个人计划
export function exportMyCulturePlanPdf(id,type) {
    let url = '/api/cultureservice/culturePlan/exportMyCulturePlanPdf?studentId=' + cryp.encrypt(id) + '&type=' + type;
    window.open(`${url}`);
}
//批量导出计划
export function exportPlanPdfList(params) {
    let url = '/api/cultureservice/culturePlan/exportPlanPdfList';
    let query = '?';
    for (let key in params) {
        query += key;

        query += '=';
        query += params[key];
        query += '&'
    }
    return url + query;
    
}
// 计划选课统计-导出
export function exporCurentPage(queryForm) {
    // queryForm["x-token"] = sessionStorage.getItem("sessionid") || "";
    let url =
        '/api/cultureservice/culturePlan/exporCurentPage';
    let queryParam = '';
    for (let key in queryForm) {
        // 去掉空参数
        if (
            key === 'pageNum_' ||
            key === 'pageSize_' ||
            key === 'total_' ||
            queryForm[key] === ''
        ) {
            continue;
        }
        queryParam += `${key}=${queryForm[key]}&`;
    }
    window.open(`${url}?${queryParam}`);
}
//批量修改培养计划-获取开关状态
export function getTurn(type,projId) {
    return fetch({
        url:
            '/api/cultureservice/PowerContron/getTurn?Type_=' +
            type+
            '&projId=' +
            projId,
        method: 'GET'
    });
}
//批量修改培养计划-开关状态改变
export function insertPower(type, val,projId) {
    return fetch({
        url:
            '/api/cultureservice/PowerContron/insertPower?Type_=' +
            type +
            '&powerValue=' +
            val +
            '&projId=' +
            projId,
        method: 'GET'
    });
}
//培养计划开放权限-制定计划按钮状态
export function findAuthPushTimeAllPermission(queryForm) {
    let queryParam = '';
    for (let key in queryForm) {
        queryParam += `${key}=${queryForm[key]}&`;
    }
    return fetch({
        url:
            '/api/cultureservice/cultureAuth/findAuthPushTimePermission?' +
            queryParam,
        method: 'GET'
    });
}
// 培养方案关联操作日志
export function cultureOperationLogInfo(data) {
    return fetch({
        url: '/api/cultureservice/cultureOperationLogInfo',
        method: 'POST',
        data
    });
}
// 培养方案关联操作日志-导出
export function exportCultureOperationLogInfo(queryForm) {
    let url =
        '/api/cultureservice/cultureOperationLogInfo/exportCultureOperationLogInfo';
    let queryParam = '';
    for (let key in queryForm) {
        // 去掉空参数
        if (
            key === 'total_'
        ) {
            continue;
        }
        queryParam += `${key}=${queryForm[key]}&`;
    }
    window.open(`${url}?${queryParam}`);
}
// 获取大课对应的小课
export function getSmallCourse(data) {
    return fetch({
        url: '/api/cultureservice/culturePlan/getSmallCourse',
        method: 'POST',
        data
    });
}
//选择大课对应的小课
export function setSmallCourse(data) {
    return fetch({
        url: '/api/cultureservice/culturePlan/setSmallCourse',
        method: 'POST',
        data
    });
}
//删除跨院系选课
export function deleteTransdisciplinaryCourse(data) {
    return fetch({
        url: '/api/cultureservice/culturePlan/deleteTransdisciplinaryCourse',
        method: 'POST',
        data
    });
}
//搜索学生外国语课程
export function queryAddCourseList(content, data) {
    return fetch({
        url: '/api/cultureservice/firstLanguageContrast/queryAddCourseList?content=' + content,
        method: 'POST',
        data
    });
}
//学生外国语课程转换
export function queryCourseListByCodes(data) {
    return fetch({
        url: '/api/cultureservice/firstLanguageContrast/queryCourseListByCodes',
        method: 'POST',
        data
    });
}

//修改培养计划状态
export function updateStatus(studentId) {
    return fetch({
       
        url: `/api/cultureservice/studentCultureRel/cancelApprove/${studentId}`,     
        method: 'GET'
    });
}
//学生外国语课程转换
export function ischeckExitRace(data) {
    return fetch({
        url: '/api/cultureservice/culturePlan/ischeckExitRace',
        method: 'POST',
        data
    });
}
/**
 * 页面导出excel
 * @param {*} data 
 */
export function exportPage(data,url="exportStudentCultureRelList",pageName="培养计划"){
    return fetch({
        url: `/api/cultureservice/studentCultureRel/${url}`,
        method: 'post',
        data: data,
        responseType: 'blob'
    }).then(res => {
        UTILS.downloadFile(res, `${pageName}列表.xls`, 'application/vnd.ms-excel;charset=utf-8');
    });
}
/**
 * 培养计划审批设置(查询)
 * @param data
 */
export function schemePlanfindResult(data) {
  return fetch({
    url:
      '/api/cultureservice/schemaPlanSetTurn/findResult',
    method: 'post',
    data
  })
}
/**
 * 培养计划审批设置(提交)
 * @param data
 */
export function schemePlanAddSet(data) {
  return fetch({
    url:
      '/api/cultureservice/schemaPlanSetTurn/addSet',
    method: 'post',
    data
  })
}
/**
 * 培养计划批量审批
 * @param data
 */
export function batchPlan(data) {
  return fetch({
    url:
      '/api/workflow/approval/through/batch',
    method: 'post',
    data
  })
}
/**
 * 教务员全量查询研究生学院
 * @param {data} data
 */
export function findAllDeptList() {
    return fetch({
        url: '/api/userservice/dept/findDept?virtualDept=0&type=1&manageDept=1',
        method: 'get',
    });
}
/**全量查询第一外国语码
 * @param {data} data
 */
export function firstLanguageContrast(id) {
    return fetch({
        url: '/api/cultureservice/firstLanguageContrast/page?managerDeptId='+id+'&pageSize_=10000&pageNum_=1',
        method: 'get',
    });
}
/**
 * 刷新计划完成情况
 * @param data
 */
export function updatePlansCompleteStatistical(data) {
    return fetch({
        url:
            '/api/cultureservice/studentCultureRel/updatePlansCompleteStatistical',
        method: 'post',
        data
    })
}
/**
 * 计划完成情况导出
 * @param data
 */
export function exportPlansCompleteStatistical(data, url = "exportPlansCompleteStatistical", pageName = "培养计划完成情况统计") {
    return fetch({
        url: `/api/cultureservice/studentCultureRel/${url}`,
        method: 'post',
        data: data,
        responseType: 'blob'
    }).then(res => {
        UTILS.downloadFile(res, `${pageName}列表.xls`, 'application/vnd.ms-excel;charset=utf-8');
    });
}